package com.cmcc.aregister.cs.util;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import com.cmcc.aregister.MyApplication;
import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.Arguments;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.constant.GlobalSetting;
import com.cmcc.aregister.cs.model.Appointment;
import com.cmcc.aregister.cs.model.Department;
import com.cmcc.aregister.cs.model.DetlEntity;
import com.cmcc.aregister.cs.model.Disease;
import com.cmcc.aregister.cs.model.Doctor;
import com.cmcc.aregister.cs.model.FamilyModel;
import com.cmcc.aregister.cs.model.Hospital;
import com.cmcc.aregister.cs.model.MastEntity;
import com.cmcc.aregister.cs.model.MemberModel;
import com.cmcc.aregister.cs.model.NoticeModel;
import com.cmcc.aregister.cs.model.Order;
import com.cmcc.aregister.cs.model.PayTypeModel;
import com.cmcc.aregister.cs.model.QuickYuyueEntity;
import com.cmcc.aregister.cs.model.Schedule;
import com.cmcc.aregister.cs.model.User;
import com.oauth.utils.EncryptUtils;

public class JsonParse
{
    private static final String TAG = "JsonParse";
    public static String no_data = MyApplication.getInstance().getString(
        R.string.no_data);
    private static MyLogger logger = MyLogger.getLogger();

    public static Map<String, Object> parseJSON(byte[] _httpResponseData,
        int _jsonParseType)
    {
        HashMap<String, Object> dataMap = new HashMap<String, Object>();
        String dataStr = "";
        try
        {
            dataStr = new String(_httpResponseData, "UTF-8");
            logger.d("reutrn str" + dataStr);
            switch (_jsonParseType)
            {
            case GlobalSetting.XML_USER_REGISTER:
                parseUserRegister(dataStr, dataMap);
                break;
            case GlobalSetting.XML_CHANGE_USER_INFO:
            case GlobalSetting.XML_CANCEL_APPOINTMENT:
            case GlobalSetting.XML_CONFIRM_ATTENTION:
            case GlobalSetting.XML_CANCEL_ATTENTION:
            case GlobalSetting.XML_CANCEL_OTHER_ORDER:
            case GlobalSetting.XML_CHECK_YCT:
                parseStatus(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_USER_INFO:
                parseUserInfo(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_ORDER_INFO:
                parseOrderInfo(dataStr, dataMap);
                break;
            case GlobalSetting.XML_HOSPITAL_LIST:
                parseHospitalList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_HOSPITAL_DETAIL:
                parseHospitalDetail(dataStr, dataMap);
                break;
            case GlobalSetting.XML_DEPARTMENT_LIST:
                parseDepartmentList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_DEPARTMENT_DETAIL:
                parseDepartmentDetail(dataStr, dataMap);
                break;
            case GlobalSetting.XML_DOCTOR_LIST:
                parseDoctorList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_DOCTOR_DETAIL:
                parseDoctorDetail(dataStr, dataMap);
                break;
            case GlobalSetting.XML_SEARCH:
                parseSearch(dataStr, dataMap);
                break;
            case GlobalSetting.XML_SCHEDULE_LIST:
                parseScheduleList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_CONFIRM_APPOINTMENT:
                parseConfirmAppointment(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_DISEASE_TYPE_LIST:
                parseGetDiseaseTypeList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_DISEASE_LIST:
                parseGetDiseaseList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_DISEASE_DETAIL:
                parseGetDiseaseDetail(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_OTHER_ORDER:
                parseGetOtherOrder(dataStr, dataMap);
                break;
            case GlobalSetting.XML_ORDER_OTHE:
                parseOrderOther(dataStr, dataMap);
                break;
            case GlobalSetting.XML_QUICK_ORDER:
                parseQuickOrder(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_HOSPITAL_PAY_TYPE_INFO:
                parseHospitalPayType(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_FAMILY_INFO:
                parseFamilyInfo(dataStr, dataMap);
                break;
            case GlobalSetting.XML_ADD_MEMBER:
            case GlobalSetting.XML_UPD_MEMBER:
            case GlobalSetting.XML_DEL_MEMBER:
                parseMemberState(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_NOTICE:
                paresNotices(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_BINDCARD:
                parseBindCard(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_PAYAGAIN:
            case GlobalSetting.XML_BOOL_BIND:
                parsePayAgain(dataStr, dataMap);
                break;
            case GlobalSetting.XML_AUTO_APPOINT_LIST:
                parseAutoAppointList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_CANCEL_AUTO_APPOINT:
            case GlobalSetting.XML_ADD_AUTO_APPOINT:
            case GlobalSetting.XML_CANCEL_HAOYUAN_TIP_TASK:
                parseCancelAutoAppoint(dataStr, dataMap);
                break;
            case GlobalSetting.XML_VALID_VIP:
                parseVaildVip(dataStr, dataMap);
                break;
            case GlobalSetting.XML_HAOYUAN_TIP_LIST:
                parseHaoyuanTipList(dataStr, dataMap);
                break;
            case GlobalSetting.XML_ADD_HAOYUAN_TIP_TASK:
                parseAddHaoyuanTipTask(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_CILENT_INFO_TASK:
                parseGetClientInfo(dataStr, dataMap);
                break;
            case GlobalSetting.XML_GET_EXTRAS_TASK:
                parseGetExtras(dataStr, dataMap);
                break;
            }
            return dataMap;
        }
        catch (Exception e)
        {
            if (ConfigUtilHelper.debug)
            {
                Log.i(TAG, "Exception:" + e.getMessage());
            }
            logger.e(e);
            return null;
        }
    }

    /**
     * 解析验证VIP
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseVaildVip(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.RESULT_CODE, jsonObject.getString("resultCode"));
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
        dataMap.put(Arguments.JSON_ISVIP, jsonObject.getString("isVIP"));
    }

    /**
     * 解析自动预约列表
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseAutoAppointList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        List<Appointment> list = new ArrayList<Appointment>();
        JSONObject obj = null;
        String resultCode = jsonObject.getString("resultCode");
        dataMap.put(Arguments.RESULT_CODE, resultCode);
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
        if (resultCode.equals("0"))
        {
            JSONArray data = jsonObject.getJSONArray("records");
            int len = data.length();
            for (int i = 0; i < len; i++)
            {
                obj = (JSONObject) data.opt(i);
                Appointment appointment = new Appointment();
                appointment.doctor_name = obj.getString("doctor_name");
                appointment.yuyue_id = obj.getString("taskId");
                appointment.unit_name = obj.getString("hospital_name");
                appointment.yuyue_state = obj.getString("appoint_status");
                appointment.begin_time = obj.getString("appoint_date");
                appointment.phone = obj.getString("appoint_mobile");
                appointment.service_desc = obj.getString("appoint_msg");
                appointment.truename = obj.getString("member_name");
                appointment.dep_name = obj.getString("section_name");
                appointment.order_no = obj.getString("order_no");
                list.add(appointment);
            }
        }
        obj = null;
        dataMap.put(Arguments.JSON_AUTO_APPOINT_LIST, list);
    }

    /**
     * 解析号源提醒列表
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseHaoyuanTipList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        List<Appointment> list = new ArrayList<Appointment>();
        JSONObject obj = null;
        String resultCode = jsonObject.getString("resultCode");
        dataMap.put(Arguments.RESULT_CODE, resultCode);
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
        if (resultCode.equals("0"))
        {
            JSONArray data = jsonObject.getJSONArray("records");
            int len = data.length();
            for (int i = 0; i < len; i++)
            {
                obj = (JSONObject) data.opt(i);
                Appointment appointment = new Appointment();
                appointment.doctor_name = obj.getString("doc_name");
                appointment.remind_type = obj.getString("remind_type");
                appointment.yuyue_id = obj.getString("taskId");
                appointment.unit_name = obj.getString("unit_name");
                appointment.yuyue_state = obj.getString("task_status");
                appointment.service_desc = obj.getString("task_msg");
                appointment.dep_name = obj.getString("dep_name");
                appointment.appoint_days = obj.getString("appoint_days");
                appointment.appoint_stop_time = obj
                    .getString("appoint_stop_time");
                appointment.appoint_start_time = obj
                    .getString("appoint_start_time");
                appointment.can_appoint = obj.getString("can_appoint");
                list.add(appointment);
            }
        }
        obj = null;
        dataMap.put(Arguments.JSON_HAOYUAN_TIP_LIST, list);
    }

    /**
     * 添加号源提醒任务
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseAddHaoyuanTipTask(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.RESULT_CODE, jsonObject.getString("resultCode"));
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
        dataMap.put(Arguments.TASKID, jsonObject.getString("taskId"));
        dataMap.put(Arguments.APPOINT_DAYS,
            jsonObject.getString("appoint_days"));
        dataMap.put(Arguments.APPOINT_STOP_TIME,
            jsonObject.getString("appoint_stop_time"));
        dataMap.put(Arguments.APPOINT_START_TIME,
            jsonObject.getString("appoint_start_time"));
        dataMap.put(Arguments.PHONE, jsonObject.getString("user_mobile"));
        dataMap.put(Arguments.HOS_NAME, jsonObject.getString("unit_name"));
        dataMap.put(Arguments.DEP_NAME, jsonObject.getString("dep_name"));
        dataMap.put(Arguments.DOC_NAME, jsonObject.getString("doc_name"));
        dataMap.put(Arguments.REMIND_TYPE, jsonObject.getString("remind_type"));
    }

    /**
     * 解析取消自动预约任务
     * 
     * @param dataStr
     * @param dataMap
     */
    private static void parseCancelAutoAppoint(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.RESULT_CODE, jsonObject.getString("resultCode"));
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
    }

    private static void paresNotices(String dataStr, Map<String, Object> dataMap)
        throws JSONException
    {
        JSONArray data = new JSONArray(dataStr);
        List<NoticeModel> list = new ArrayList<NoticeModel>();
        int len = data.length();
        JSONObject obj = null;
        for (int i = 0; i < len; i++)
        {
            obj = (JSONObject) data.opt(i);
            NoticeModel notice = new NoticeModel();
            notice.id = obj.getInt("ID");
            notice.title = obj.getString("TITLE");
            notice.content = obj.getString("CONTENT");
            notice.top = obj.getInt("TOP") == 1 ? true : false;
            notice.link = obj.getString("LINK");
            notice.image = obj.getString("IMAGE");
            notice.state = obj.getString("STATE");
            notice.create_time = obj.getString("CREATE_TIME");
            list.add(notice);
        }
        obj = null;
        dataMap.put(Arguments.XML_NOTICE_LIST, list);
    }

    private static void parseMemberState(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("state"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("msg"));
    }

    /**
     * 解析家庭
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseFamilyInfo(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        int state = jsonObject.getInt("state");
        if (state > 0)
        {
            JSONObject familyObject = jsonObject.getJSONObject("family");
            FamilyModel family = new FamilyModel();
            family.f_id = familyObject.getString("F_ID");
            family.phone = familyObject.getString("PHONE");
            family.card = familyObject.getString("CARD");
            family.card = familyObject.getString("CARD_TYPE");
            family.linkman = familyObject.getString("LINKMAN");
            family.city_id = familyObject.getString("CITY_ID");
            family.area_id = familyObject.getString("AREA_ID");
            family.addr = familyObject.getString("ADDR");
            family.person_num = familyObject.getString("PERSON_NUM");
            family.upd_count = familyObject.getString("UPD_COUNT");
            family.f_state = familyObject.getString("F_STATE");
            family.yuyue_num = familyObject.getString("YUYUE_NUM");
            family.email = familyObject.getString("EMAIL");
            family.last_num = familyObject.getString("LAST_NUM");
            List<MemberModel> members = new ArrayList<MemberModel>();
            JSONArray data = jsonObject.getJSONArray("member");
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                members.add(parseMenber((JSONObject) data.opt(i)));
            }
            family.members = members;
            dataMap.put(Arguments.XML_FAMILY_INFO, family);
        }
    }

    /**
     * 解析成员
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static MemberModel parseMenber(JSONObject jsonObject)
        throws JSONException
    {
        MemberModel member = new MemberModel();
        member.member_id = getString(jsonObject.getString("MEMBER_ID"));
        member.truename = getString(jsonObject.getString("TRUENAME"));
        member.card = getString(jsonObject.getString("CARD"));
        member.card_type = getString(jsonObject.getString("CARD_TYPE"));
        member.phone = getString(jsonObject.getString("PHONE"));
        member.birth = getString(jsonObject.getString("BIRTH"));
        member.sex = jsonObject.getInt("SEX");
        member.m_deleted = getString(jsonObject.getString("M_DELETED"));
        member.social_card = getString(jsonObject.getString("SOCIAL_CARD"));
        member.relation = jsonObject.getInt("RELATION");
        return member;
    }

    private static String getString(String str)
    {
        return str == null || "null".equalsIgnoreCase(str) ? "" : str;
    }

    /**
     * 解析医院支持的支付方式
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseHospitalPayType(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONArray data = new JSONArray(dataStr);
        List<PayTypeModel> list = new ArrayList<PayTypeModel>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parsePayType((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_PAYTYPE_LIST, list);
    }

    private static PayTypeModel parsePayType(JSONObject jsonObject)
        throws JSONException
    {
        PayTypeModel payType = new PayTypeModel();
        payType.cfg_code = jsonObject.getString("cfg_code");
        payType.cfg_value = jsonObject.getString("cfg_value");
        payType.merchantcode = jsonObject.getString("merchantcode");
        return payType;
    }

    /**
     * 解析注册返回信息 { "status":"0", "message":"ok",
     * " health_card":"12dfsdfdsddddsfasda3" }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseUserRegister(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        String status = jsonObject.getString("status");
        if ("0".equals(status))
        {
            String health_card = jsonObject.get("health_card").toString();
            dataMap.put(Arguments.XML_HEALTH_CARD, health_card);
        }
        dataMap.put(Arguments.XML_STATUS, status);
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
    }

    /**
     * 解析查询绑定结果
     * {"state":"0","msg":"查询成功",data{cardNum:"",userId:"",mobileNum:"",
     * bindUserId:""}}
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseBindCard(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        String status = jsonObject.getString("state");
        dataMap.put(Arguments.XML_STATUS, status);
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("msg"));
        // 绑定的信息
        if ("1".equals(status))
        {
            JSONObject data = jsonObject.getJSONObject("data");
            dataMap.put("cardNum", data.getString("cardNum"));
            dataMap.put("userId", data.getString("userId"));
            dataMap.put("mobileNum", data.getString("mobileNum"));
            dataMap.put("bindUserId", data.getString("bindUserId"));
        }
    }

    /**
     * 解析再次支付
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parsePayAgain(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        String status = jsonObject.getString("state");
        dataMap.put(Arguments.XML_STATUS, status);
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("msg"));
    }

    /**
     * 解析操作结果 { "status":"0", "message":"ok"}
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseStatus(String dataStr, Map<String, Object> dataMap)
        throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
    }

    /**
     * 解析用户信息 { "status":"0", "message":"ok", "data":{ "name":"杨小梅",
     * "birth":"1980-02-30", "sex":"1", "card":"342333334333333333",
     * "social_card":"" } }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseUserInfo(String dataStr,
        Map<String, Object> dataMap) throws Exception
    {
        // 返回报文解密
        String desDataStr = EncryptUtils.decode(dataStr);
        JSONObject jsonObject = new JSONObject(desDataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        User user = new User();
        try
        {
            JSONObject data = jsonObject.getJSONObject("data");
            user.name = data.getString("name");
            user.birth = data.getString("birth");
            user.sex = data.getString("sex");
            user.card = data.getString("card");
            user.social_card = data.getString("social_card");
        }
        catch (Exception e)
        {
            // TODO: handle exception
        }
        dataMap.put(Arguments.XML_USER, user);
    }

    /**
     * 解析用户订单信息{ "status":"0", "message":"ok", "data":[{ "yuyue_id":12,
     * "order_no":"20323452" "unit_name":"北京大学深圳医院", "dep_name":"妇产科",
     * "doctor_name":"杨小梅", "zcname":"主任医师", "guahao_amt":9,
     * "to_date":"2011-09-25", "begin_time":"08:00", "end_time":"09:00",
     * "yuyue_state":1 }, ... ] }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseOrderInfo(String dataStr,
        Map<String, Object> dataMap) throws Exception
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "本地用户订单:" + dataStr);
        }
        // 返回报文解密
        String desDataStr = EncryptUtils.decode(dataStr);
        has_yuyue_num = 0;
        jiuzhen_yuyue_num = 0;
        shuangyue_yuyue_num = 0;
        tingzhen_yuyue_num = 0;
        JSONObject jsonObject = new JSONObject(desDataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "--message--" + jsonObject.getString("message"));
        }
        JSONArray data = jsonObject.getJSONArray("data");
        List<Appointment> list = new ArrayList<Appointment>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseAppointment((JSONObject) data.opt(i)));
        }
        Collections.reverse(list);
        dataMap.put(Arguments.XML_ORDER_LIST, list);
        dataMap.put(Arguments.XML_YUYUE_NUM, has_yuyue_num);
        dataMap.put(Arguments.XML_JIUZHEN_NUM, jiuzhen_yuyue_num);
        dataMap.put(Arguments.XML_TINGZHEN_NUM, tingzhen_yuyue_num);
        dataMap.put(Arguments.XML_SHUANGYUE_NUM, shuangyue_yuyue_num);
    }

    /**
     * 解析医院列表
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseHospitalList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "------医院列表--------" + jsonObject);
        }
        JSONArray data = jsonObject.getJSONArray("data");
        List<Hospital> list = new ArrayList<Hospital>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseHospital((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_CURRPAGE, jsonObject.getString("currPage"));
        dataMap.put(Arguments.XML_ALLPAGE, jsonObject.getString("allPage"));
        dataMap.put(Arguments.XML_HOSPITAL_LIST, list);
    }

    /**
     * 解析医院详情 { "status":"0", "message":"ok", "data":{ "unit_id":12,
     * "unit_name":"北京大学深圳医院", "address":"广东省深圳市福田莲花路1120号",
     * "bus_route":"sdfsdfadfadsfads", "phone":"0755-28322772", "dep_list":[ {
     * "dep_id":123, "dep_name":"妇产科", "key_level":0, "left_num":90,
     * "is_attention":1 }, ... ] } }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseHospitalDetail(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "------医院详情--------" + jsonObject);
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        JSONObject data = jsonObject.getJSONObject("data");
        Hospital hospital = new Hospital();
        hospital.unit_id = data.getString("unit_id");
        hospital.unit_name = data.getString("unit_name");

        // 新添加的再次获取医院号源（目前只因为首页静态广告位）
        if (data.has("left_num"))
        {
            String left_num = data.getString("left_num");
            if ("null".equals(left_num) || "".equals(left_num))
            {
                hospital.left_num = "0";
            }
            else
            {
                hospital.left_num = left_num;
            }
        }
        else
        {
            hospital.left_num = "0";
        }
        String address = data.getString("address");
        if ("".equals(address) || "null".equals(address))
        {
            hospital.address = no_data;
        }
        else
        {
            hospital.address = address;
        }
        hospital.unit_level = Utils.getHospitalLevelStr(data
            .getString("unit_level"));
        if (data.has("bus_route"))
        {
            String bus_route = data.getString("bus_route");
            if ("".equals(bus_route) || "null".equals(bus_route))
            {
                hospital.bus_route = no_data;
            }
            else
            {
                hospital.bus_route = changeErrorStr(bus_route);
            }
        }
        else
        {
            hospital.bus_route = no_data;
        }
        if (data.has("phone"))
        {
            String phone = data.getString("phone");
            if ("".equals(phone) || "null".equals(phone))
            {
                hospital.phone = no_data;
            }
            else
            {
                hospital.phone = phone;
            }
        }
        else
        {
            hospital.bus_route = no_data;
        }
        JSONArray dataArray = data.getJSONArray("dep_list");
        List<Department> list = new ArrayList<Department>();
        int length = dataArray.length();
        for (int i = 0; i < length; i++)
        {
            JSONObject jsonArray = (JSONObject) dataArray.opt(i);
            Department department = new Department();
            department.dep_id = jsonArray.getString("dep_id");
            department.dep_name = jsonArray.getString("dep_name");
            department.key_level = Utils.getDepartmentLevelStr(jsonArray
                .getString("key_level"));
            if (jsonArray.has("left_num"))
            {
                String left_num = jsonArray.getString("left_num");
                if ("null".equals(left_num) || "".equals(left_num))
                {
                    department.left_num = "0";
                }
                else
                {
                    department.left_num = left_num;
                }
            }
            else
            {
                department.left_num = "0";
            }

            department.area_type = jsonArray.getString("area_type");
            department.is_attention = jsonArray.getString("is_attention");
            department.unit_id = jsonArray.getString("unit_id");
            department.unit_name = jsonArray.getString("unit_name");
            department.is_attention = jsonArray.getString("is_attention");
            list.add(department);
        }
        hospital.dep_list = list;
        dataMap.put(Arguments.XML_HOSPITAL, hospital);
    }

    /**
     * 解析科室列表{ "status":"0", "message":"ok", "currPage":1, "allPage":12,
     * "data":[{ "dep_id":123, "dep_name":"妇产科", "unit_id":12,
     * "unit_name":"北京大学深圳医院", "key_level":0, "left_num":90, "area_type ":0,
     * "is_attention":1 }, ... ] }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseDepartmentList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "---科室列表------" + jsonObject);
        }
        JSONArray data = jsonObject.getJSONArray("data");
        List<Department> list = new ArrayList<Department>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseDepartment((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_CURRPAGE, jsonObject.getString("currPage"));
        dataMap.put(Arguments.XML_ALLPAGE, jsonObject.getString("allPage"));
        dataMap.put(Arguments.XML_DEPARTMENT_LIST, list);
    }

    /**
     * 解析科室详情 { "status":"0", "message":"ok",
     * " dep_intro":" kdkdkdjskdjfksdjfkdsfj", "doctor_list":[{ "doctor_id":121,
     * "doctor_name":"杨小梅", "image":"http://211.139.161.120:/upload/2/232.jpg",
     * "left_num ":23, "is_attention":1, }, ... ] }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseDepartmentDetail(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "---科室详情------" + jsonObject);
        }
        Department department = new Department();
        try
        {
            String dep_intro = jsonObject.getString("dep_intro").trim();
            if ("".equals(dep_intro) || "null".equals(dep_intro))
            {
                department.dep_intro = no_data;
            }
            else
            {
                department.dep_intro = changeErrorStr(dep_intro.replace("<br>",
                    ""));
            }
            JSONArray data = jsonObject.getJSONArray("doctor_list");
            List<Doctor> list = new ArrayList<Doctor>();
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                JSONObject jsonArray = (JSONObject) data.opt(i);
                Doctor doctor = new Doctor();
                doctor.area_type = jsonArray.getString("area_type");
                doctor.doctor_id = jsonArray.getString("doctor_id");
                doctor.doctor_name = jsonArray.getString("doctor_name");
                doctor.detail = jsonArray.getString("detail");
                doctor.dep_name = jsonArray.getString("dep_name");
                doctor.dep_id = jsonArray.getString("dep_id");
                doctor.unit_id = jsonArray.getString("unit_id");
                doctor.image = jsonArray.getString("image");
                doctor.is_attention = jsonArray.getString("is_attention");
                doctor.unit_name = jsonArray.getString("unit_name");
                if (jsonArray.has("guahao_amt"))
                {
                    doctor.guahao_amt = jsonArray.getString("guahao_amt");
                }
                else
                {
                    doctor.guahao_amt = "0";
                }
                if (jsonArray.has("left_num"))
                {
                    String left_num = jsonArray.getString("left_num");
                    if ("null".equals(left_num) || "".equals(left_num))
                    {
                        doctor.left_num = "0";
                    }
                    else
                    {
                        doctor.left_num = left_num;
                    }
                }
                else
                {
                    doctor.left_num = "0";
                }
                if (jsonArray.has("sch_masts"))
                {
                    JSONArray data_sch_masts = jsonArray
                        .getJSONArray("sch_masts");
                    List<Schedule> list_sch_masts = new ArrayList<Schedule>();
                    int l = data_sch_masts.length();
                    for (int k = 0; k < l; k++)
                    {
                        JSONObject jsonArray_sch_masts = (JSONObject) data_sch_masts
                            .opt(k);
                        Schedule schedule = new Schedule();
                        schedule.schedule_id = jsonArray_sch_masts
                            .getString("schedule_id");
                        schedule.to_date = jsonArray_sch_masts
                            .getString("to_date");
                        schedule.time_type = Utils
                            .getTimeType(jsonArray_sch_masts
                                .getString("time_type"));
                        if (jsonArray_sch_masts.has("left_num"))
                        {
                            String left_num = jsonArray_sch_masts
                                .getString("left_num");
                            if ("null".equals(left_num) || "".equals(left_num))
                            {
                                schedule.left_num = "0";
                            }
                            else
                            {
                                schedule.left_num = left_num;
                            }
                        }
                        else
                        {
                            schedule.left_num = "0";
                        }
                        schedule.doctor = doctor;
                        list_sch_masts.add(schedule);
                    }
                    doctor.schedule_list = list_sch_masts;
                }
                else
                {
                    doctor.schedule_list = new ArrayList<Schedule>();
                }

                list.add(doctor);
            }
            department.doctor_list = list;
        }
        catch (Exception e)
        {
            // TODO: handle exception
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_DEPARTMENT, department);
    }

    /**
     * 解析医生列表 { "status":"0", "message":"ok", "currPage":1, "allPage":12,
     * "data":[{ "doctor_id":121, "doctor_name":"杨小梅", "guahao_amt":7,
     * "detail":"dkdkdkdjfksjdfksdjddddd",
     * "image":"http://211.139.161.120:/upload/2/232.jpg", "dep_id":123,
     * "dep_name":"妇产科", "unit_id":12, "unit_name":"北京大学深圳医院", "area_type ":0,
     * "is_attention":1, "sch_masts":[{ "schedule_id":232,
     * "to_date":"2011-12-02", "time_type":"am", "left_num":2 }, ... ] }, ... ]
     * }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseDoctorList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "------医生列表--------" + jsonObject);
        }
        JSONArray data = jsonObject.getJSONArray("data");
        List<Doctor> list = new ArrayList<Doctor>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseDoctor((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_CURRPAGE, jsonObject.getString("currPage"));
        dataMap.put(Arguments.XML_ALLPAGE, jsonObject.getString("allPage"));
        dataMap.put(Arguments.XML_DOCTOR_LIST, list);
    }

    /**
     * 解析医生详情 { "status":"0", "message":"ok",
     * "detail":"dkdkdkdjfksjdfksdjddddd"}
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseDoctorDetail(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "------医生详情--------" + jsonObject);
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        if (jsonObject.has("detail"))
        {
            String detail = jsonObject.getString("detail").trim();
            if ("".equals(detail) || "null".equals(detail))
            {
                dataMap.put(Arguments.XML_DETAIL, no_data);
            }
            else
            {
                dataMap.put(Arguments.XML_DETAIL, detail);
            }
        }
    }

    /**
     * 解析名医名院查询结果 { "status":"0", "message":"ok", "currPage":1, "allPage":12,
     * " search_type":1, "data":[{ "dep_id":123, "dep_name":"妇产科", "unit_id":12,
     * "unit_name":"北京大学深圳医院" }, ... ] }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseSearch(String dataStr, Map<String, Object> dataMap)
        throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_CURRPAGE, jsonObject.getString("currPage"));
        dataMap.put(Arguments.XML_ALLPAGE, jsonObject.getString("allPage"));
        String search_type = jsonObject.getString("search_type");
        JSONArray data = jsonObject.getJSONArray("data");
        if ("0".equals(search_type))
        {
            List<Hospital> list = new ArrayList<Hospital>();
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                list.add(parseHospital((JSONObject) data.opt(i)));
            }
            dataMap.put(Arguments.XML_HOSPITAL_LIST, list);
        }
        else if ("1".equals(search_type))
        {
            List<Department> list = new ArrayList<Department>();
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                list.add(parseDepartment((JSONObject) data.opt(i)));
            }
            dataMap.put(Arguments.XML_DEPARTMENT_LIST, list);
        }
        else
        {
            List<Doctor> list = new ArrayList<Doctor>();
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                list.add(parseDoctor((JSONObject) data.opt(i)));
            }
            dataMap.put(Arguments.XML_DOCTOR_LIST, list);
        }
    }

    /**
     * 解析出诊列表 { "status":"0", "message":"ok", "data":[{ "detl_id":123,
     * "begin_time":"08:00", "end_time":"09:00", "left_num":12 }, ... ] }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseScheduleList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "出诊列表:" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        JSONArray data = jsonObject.getJSONArray("data");
        List<Schedule> list = new ArrayList<Schedule>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseSchedule((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_SCHEDULE_LIST, list);
    }

    /**
     * 解析提交预约结果 { "status":"0", "message":"ok", "data":{ "yuyue_id":123,
     * "order_no":"232222232" } }
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseConfirmAppointment(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "本地提交订单结果：" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.ACTIVITY_JUMP_TYPE, "0");
        int state = jsonObject.getInt("status");
        dataMap.put(Arguments.XML_STATUS, jsonObject.getInt("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        if (state == 0)
        {
            Appointment appointment = new Appointment();
            JSONObject data = jsonObject.getJSONObject("data");
            appointment.yuyue_id = data.getString("yuyue_id");
            appointment.order_no = data.getString("order_no");
            dataMap.put(Arguments.XML_APPOINTMENT, appointment);
        }
        /*
         * if (jsonObject.has("health_card")) {
         * dataMap.put(Arguments.XML_HEALTH_CARD,
         * jsonObject.getString("health_card")); } if (jsonObject.has("data")) {
         * JSONObject data = jsonObject.getJSONObject("data"); Appointment
         * appointment = new Appointment(); appointment.yuyue_id =
         * data.getString("yuyue_id"); appointment.order_no =
         * data.getString("order_no"); dataMap.put(Arguments.XML_APPOINTMENT,
         * appointment); }
         */
    }

    /**
     * 解析疾病分类 { status: 0, message: "查询成功", data: [ { catid: "1", catname: "内科",
     * cat_no: "A", list: [ { catid: "15", catname: "呼吸内科", cat_no: "A01" }, {
     * catid: "22", catname: "风湿科", cat_no: "A08" } ] } ] }
     * 
     * 
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetDiseaseTypeList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        JSONArray data = jsonObject.getJSONArray("data");
        List<Disease> list = new ArrayList<Disease>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseDiseaseType((JSONObject) data.opt(i)));
            JSONObject listObject = (JSONObject) data.opt(i);
            JSONArray dataArray = listObject.getJSONArray("list");
            int listLength = dataArray.length();
            for (int j = 0; j < listLength; j++)
            {
                list.add(parseDiseaseType((JSONObject) dataArray.opt(j)));
            }
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_DISEASE_LIST, list);
    }

    /**
     * 解析疾病列表 { "status":"0", "message":"ok", "currPage":1, "allPage":12,
     * "data":[{ "ill_id":121, "ill_name":"小儿感冒" "ill_intro":"…" }, ... ] }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetDiseaseList(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        JSONArray data = jsonObject.getJSONArray("data");
        List<Disease> list = new ArrayList<Disease>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            list.add(parseDisease((JSONObject) data.opt(i)));
        }
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_CURRPAGE, jsonObject.getString("currPage"));
        dataMap.put(Arguments.XML_ALLPAGE, jsonObject.getString("allPage"));
        dataMap.put(Arguments.XML_DISEASE_LIST, list);
    }

    /**
     * 解析疾病信息{ "status":"0", "message":"ok", "data":[{ "ill_name":"小儿感冒",
     * "ill_intro":"sdkjfsdfjdksfsd" "casue":… Complication:….. Relation_dep:…
     * }, ] }
     * 
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetDiseaseDetail(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        JSONObject data = jsonObject.getJSONObject("data");
        Disease disease = new Disease();
        disease.ill_name = data.getString("ill_name");
        disease.ill_intro = changeErrorStr(data.getString("ill_intro"));
        disease.ill_cause = changeErrorStr(data.getString("cause"));
        disease.ill_symptoms = changeErrorStr(data.getString("complication"));
        disease.relation_dep = changeErrorStr(data.getString("relation_dep"));
        dataMap.put(Arguments.XML_DISEASE, disease);
    }

    /**
     * 解析异地就医订单 {"status":0,"message":"ok","data":[{"skc_orderno":
     * "DYYX201111231548160109","userdesc":
     * "\u590d\u65e6\u5927\u5b66\u9644\u5c5e\u534e\u5c71\u533b\u9662\u6297\u751f\u7d20\u7814\u7a76\u6240\u738b\u660e\u8d35"
     * ,"besttime":"\u665a\u4e0a19\u70b9-20\u70b9","orderstatus":"6"} ... ] }
     * 
     * 
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetOtherOrder(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "异地用户订单:" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        JSONArray data = jsonObject.getJSONArray("data");
        List<Order> list = new ArrayList<Order>();
        int length = data.length();
        for (int i = 0; i < length; i++)
        {
            JSONObject jsonArray = (JSONObject) data.opt(i);
            Order order = new Order();
            order.skc_orderno = jsonArray.getString("skc_orderno");
            order.besttime = jsonArray.getString("besttime");
            order.orderstatus = jsonArray.getString("orderstatus");
            order.userdesc = jsonArray.getString("userdesc");
            list.add(order);
        }
        Collections.reverse(list);
        dataMap.put(Arguments.XML_OTHER_ORDER_LIST, list);
    }

    /**
     * 解析异地就医下单{ "status":"0", "message":"ok",
     * "order_no":"dskjfsdkjfdksjkjeke993" }
     * 
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseOrderOther(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "异地下单dataStr:" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.ACTIVITY_JUMP_TYPE, "1");
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        dataMap.put(Arguments.XML_ORDER_NO, jsonObject.getString("order_no"));
    }

    /**
     * 解析快速预约
     * 
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     * @throws UnsupportedEncodingException
     */
    private static void parseQuickOrder(String dataStrB,
        Map<String, Object> dataMap) throws JSONException,
        UnsupportedEncodingException
    {
        String dataStr = new String(dataStrB.getBytes(), "utf-8");
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "快速预约dataStr:" + dataStr);
        }
        QuickYuyueEntity quick = new QuickYuyueEntity();
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.ACTIVITY_JUMP_TYPE, "1");
        dataMap.put(Arguments.XML_STATUS, jsonObject.getString("status"));
        dataMap.put(Arguments.XML_MESSAGE, jsonObject.getString("message"));
        JSONObject dataInfo = jsonObject.getJSONObject("info");
        quick.moblie = (String) dataInfo.get("moblie");
        quick.unit_id = (String) dataInfo.get("unit_id");
        quick.unit_name = (String) dataInfo.get("unit_name");
        quick.dep_name = (String) dataInfo.get("dep_name");
        quick.doctor_name = (String) dataInfo.get("doctor_name");
        quick.zcname = (String) dataInfo.get("zcname");
        quick.truename = (String) dataInfo.get("truename");
        quick.clinic_no = (String) dataInfo.get("clinic_no");
        quick.doctor_id = (String) dataInfo.get("doctor_id");
        quick.dep_id = (String) dataInfo.get("dep_id");

        JSONArray dataMast = jsonObject.getJSONArray("mast");
        List<MastEntity> listMast = new ArrayList<MastEntity>();
        int length = dataMast.length();
        for (int i = 0; i < length; i++)
        {
            MastEntity mMastEntity = new MastEntity();
            JSONObject obj = (JSONObject) dataMast.opt(i);
            mMastEntity.schedule_id = obj.getString("schedule_id");
            mMastEntity.dep_id = obj.getString("dep_id");
            mMastEntity.dep_name = obj.getString("dep_name");
            mMastEntity.doctor_id = obj.getString("doctor_id");
            mMastEntity.doctor_name = obj.getString("doctor_name");
            mMastEntity.to_date = obj.getString("to_date");
            mMastEntity.time_type_desc = obj.getString("time_type_desc");
            mMastEntity.level_name = obj.getString("level_name");
            mMastEntity.guahao_amt = obj.getString("guahao_amt");
            mMastEntity.left_num = obj.getString("left_num");
            listMast.add(mMastEntity);
        }
        quick.mMastEntity = listMast;

        JSONArray dataDetl = jsonObject.getJSONArray("detl");
        List<DetlEntity> listDetl = new ArrayList<DetlEntity>();
        length = dataDetl.length();
        for (int i = 0; i < length; i++)
        {
            DetlEntity mDetlEntity = new DetlEntity();
            JSONObject obj = (JSONObject) dataDetl.opt(i);
            mDetlEntity.detl_id = obj.getString("detl_id");
            mDetlEntity.schedule_id = obj.getString("schedule_id");
            mDetlEntity.dep_id = obj.getString("dep_id");
            mDetlEntity.dep_name = obj.getString("dep_name");
            mDetlEntity.doctor_id = obj.getString("doctor_id");
            mDetlEntity.doctor_name = obj.getString("doctor_name");
            mDetlEntity.time_type_desc = obj.getString("time_type_desc");
            mDetlEntity.level_name = obj.getString("level_name");
            mDetlEntity.guahao_amt = obj.getString("guahao_amt");
            mDetlEntity.begin_time = obj.getString("begin_time");
            mDetlEntity.end_time = obj.getString("end_time");
            mDetlEntity.left_num = obj.getString("left_num");
            listDetl.add(mDetlEntity);
        }
        quick.mDetlEntity = listDetl;
        dataMap.put(Arguments.XML_QUICK_DATA, quick);
    }

    // --------------------
    private static int has_yuyue_num = 0; // 1 预约成功；2 已付费）
    private static int tingzhen_yuyue_num = 0; // 0 医院停诊
    private static int shuangyue_yuyue_num = 0; // 3 爽约
    private static int jiuzhen_yuyue_num = 0; // 4 就诊

    /**
     * 解析预约
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Appointment parseAppointment(JSONObject jsonObject)
        throws JSONException
    {
        Appointment appointment = new Appointment();
        appointment.yuyue_id = jsonObject.getString("yuyue_id");
        appointment.order_no = jsonObject.getString("order_no");
        appointment.unit_name = jsonObject.getString("unit_name");
        appointment.unit_id = jsonObject.getString("unit_id");
        appointment.dep_name = jsonObject.getString("dep_name");
        appointment.doctor_name = jsonObject.getString("doctor_name");
        appointment.zcname = jsonObject.getString("zcname");
        appointment.guahao_amt = jsonObject.getString("guahao_amt");
        appointment.to_date = jsonObject.getString("to_date");
        appointment.begin_time = jsonObject.getString("begin_time");
        appointment.end_time = jsonObject.getString("end_time");
        appointment.yuyue_state = jsonObject.getString("yuyue_state");
        if (appointment.yuyue_state.equals("0"))
        {
            tingzhen_yuyue_num += 1;
        }
        if (appointment.yuyue_state.equals("1")
            || appointment.yuyue_state.equals("2"))
        {
            has_yuyue_num += 1;
        }
        if (appointment.yuyue_state.equals("3"))
        {
            shuangyue_yuyue_num += 1;
        }
        if (appointment.yuyue_state.equals("4"))
        {
            jiuzhen_yuyue_num += 1;
        }
        appointment.dep_id = jsonObject.getString("dep_id");
        appointment.doctor_id = jsonObject.getString("doctor_id");
        appointment.truename = jsonObject.getString("truename");
        appointment.clinic_no = jsonObject.getString("clinic_no");
        appointment.phone = jsonObject.getString("phone");
        appointment.truename=jsonObject.getString("truename");
        appointment.chn_name=jsonObject.getString("chn_name");
        return appointment;
    }

    /**
     * 解析医院
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Hospital parseHospital(JSONObject jsonObject)
        throws JSONException
    {
        Hospital hospital = new Hospital();
        hospital.unit_id = jsonObject.getString("unit_id");
        hospital.unit_name = jsonObject.getString("unit_name");
        String address = jsonObject.getString("address");
        if ("".equals(address) || "null".equals(address))
        {
            hospital.address = no_data;
        }
        else
        {
            hospital.address = address;
        }
        hospital.unit_level = Utils.getHospitalLevelStr(jsonObject
            .getString("unit_level"));
        hospital.image = jsonObject.getString("image");
        if (jsonObject.has("left_num"))
        {
            String left_num = jsonObject.getString("left_num");
            if ("null".equals(left_num) || "".equals(left_num))
            {
                hospital.left_num = "0";
            }
            else
            {
                hospital.left_num = left_num;
            }
        }
        else
        {
            hospital.left_num = "0";
        }
        String area_type = jsonObject.getString("area_type");
        if ("".equals(area_type) || "null".equals(area_type))
        {
            hospital.area_type = "0";
        }
        else
        {
            hospital.area_type = area_type;
        }
        hospital.is_attention = jsonObject.getString("is_attention");
        return hospital;
    }

    /**
     * 解析科室
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Department parseDepartment(JSONObject jsonObject)
        throws JSONException
    {
        Department department = new Department();
        department.dep_id = jsonObject.getString("dep_id");
        department.dep_name = jsonObject.getString("dep_name");
        department.unit_id = jsonObject.getString("unit_id");
        department.unit_name = jsonObject.getString("unit_name");
        department.key_level = Utils.getDepartmentLevelStr(jsonObject
            .getString("key_level"));
        if (jsonObject.has("left_num"))
        {
            String left_num = jsonObject.getString("left_num");
            if ("null".equals(left_num) || "".equals(left_num))
            {
                department.left_num = "0";
            }
            else
            {
                department.left_num = left_num;
            }
        }
        else
        {
            department.left_num = "0";
        }
        department.area_type = jsonObject.getString("area_type");
        department.is_attention = jsonObject.getString("is_attention");
        return department;
    }

    /**
     * 解析医生
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Doctor parseDoctor(JSONObject jsonObject)
        throws JSONException
    {
        Doctor doctor = new Doctor();
        doctor.doctor_id = jsonObject.getString("doctor_id");
        doctor.doctor_name = jsonObject.getString("doctor_name");
        if (jsonObject.has("guahao_amt"))
        {
            doctor.guahao_amt = jsonObject.getString("guahao_amt");
        }
        doctor.detail = changeErrorStr(jsonObject.getString("detail"));
        doctor.image = jsonObject.getString("image");
        doctor.dep_id = jsonObject.getString("dep_id");
        doctor.dep_name = jsonObject.getString("dep_name");
        doctor.unit_id = jsonObject.getString("unit_id");
        doctor.unit_name = jsonObject.getString("unit_name");
        doctor.area_type = jsonObject.getString("area_type");
        doctor.is_attention = jsonObject.getString("is_attention");
        if (jsonObject.has("sch_masts"))
        {
            JSONArray data = jsonObject.getJSONArray("sch_masts");
            List<Schedule> list = new ArrayList<Schedule>();
            int length = data.length();
            for (int i = 0; i < length; i++)
            {
                JSONObject jsonArray = (JSONObject) data.opt(i);
                Schedule schedule = new Schedule();
                schedule.schedule_id = jsonArray.getString("schedule_id");
                schedule.to_date = jsonArray.getString("to_date");
                schedule.time_type = Utils.getTimeType(jsonArray
                    .getString("time_type"));
                if (jsonArray.has("left_num"))
                {
                    String left_num = jsonArray.getString("left_num");
                    if ("null".equals(left_num) || "".equals(left_num))
                    {
                        schedule.left_num = "0";
                    }
                    else
                    {
                        schedule.left_num = left_num;
                    }
                }
                else
                {
                    schedule.left_num = "0";
                }
                schedule.doctor = doctor;
                list.add(schedule);
            }
            doctor.schedule_list = list;
        }
        else
        {
            doctor.schedule_list = new ArrayList<Schedule>();
        }
        return doctor;
    }

    /**
     * 解析出诊
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Schedule parseSchedule(JSONObject jsonObject)
        throws JSONException
    {
        Schedule schedule = new Schedule();
        schedule.detl_id = jsonObject.getString("detl_id");
        schedule.begin_time = jsonObject.getString("begin_time");
        schedule.end_time = jsonObject.getString("end_time");
        if (jsonObject.has("left_num"))
        {
            String left_num = jsonObject.getString("left_num");
            if ("null".equals(left_num) || "".equals(left_num))
            {
                schedule.left_num = "0";
            }
            else
            {
                schedule.left_num = left_num;
            }
        }
        else
        {
            schedule.left_num = "0";
        }
        return schedule;
    }

    /**
     * 解析疾病分类
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Disease parseDiseaseType(JSONObject jsonObject)
        throws JSONException
    {
        Disease disease = new Disease();
        disease.cat_id = jsonObject.getString("catid");
        disease.cat_name = jsonObject.getString("catname");
        disease.cat_no = changeErrorStr(jsonObject.getString("cat_no"));
        return disease;
    }

    /**
     * 解析疾病
     * 
     * @param jsonObject
     * @return
     * @throws JSONException
     */
    private static Disease parseDisease(JSONObject jsonObject)
        throws JSONException
    {
        Disease disease = new Disease();
        disease.ill_id = jsonObject.getString("ill_id");
        disease.ill_name = jsonObject.getString("ill_name");
        disease.ill_intro = changeErrorStr(jsonObject.getString("ill_intro"));
        return disease;
    }

    /**
     * 解析获取推送用户信息
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetClientInfo(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "获取推送用户信息：" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.RESULT_CODE, jsonObject.getString("resultCode"));
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
    }

    /**
     * 解析获取推送信息参数
     * @param dataStr
     * @param dataMap
     * @throws JSONException
     */
    private static void parseGetExtras(String dataStr,
        Map<String, Object> dataMap) throws JSONException
    {
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "获取推送信息参数：" + dataStr);
        }
        JSONObject jsonObject = new JSONObject(dataStr);
        dataMap.put(Arguments.RESULT_CODE, jsonObject.getString("resultCode"));
        dataMap.put(Arguments.RESULT_MSG, jsonObject.getString("resultMsg"));
        String state = jsonObject.getString("resultCode");
        if ("0".equals(state))
        {
            JSONObject extras = jsonObject.getJSONObject("extras");
            dataMap.put(Arguments.BUS_TYPE, extras.get(Arguments.BUS_TYPE));
            dataMap.put(Arguments.URL, extras.get(Arguments.URL));
        }
    }

    public static String changeErrorStr(String str)
    {
        String string = str.trim();
        String result = "";
        if ("".equals(string) || "null".equals(string)
            || (string.endsWith("null") && string.length() == 6))
        {
            result = no_data;
        }
        else
        {
            result = string;
        }
        return result;
    }
}
